<template>
	<view class="testdriveresult">
		<image v-if="test_drive_img" class="testdrive_bk_img" :src="picUrl+test_drive_img" mode="widthFix"></image>
		<view class="testdrive_result_box">
			<view v-if="info.sign_status==0" class="code_img_box">
				<image class="code_img" :src="picUrl+info.qr_code">
				</image>
				<view class="mt-5 f-12">未试驾</view>
			</view>
			<view v-if="info.sign_status==1||info.sign_status==2" class="code_img_box">
				<image class="code_img_def" :src="picUrl+info.qr_code">
				</image>
				<view class="mt-5 f-12">{{info.sign_status==1?'已试驾':'已取消'}}</view>
			</view>
			<view class="ticket_userinfo_box">
				<view class="ticket_userinfo_cell">
					<view class="c-gray">姓名</view>
					<view class="">{{info.name}}</view>
				</view>
				<view class="ticket_userinfo_cell">
					<view class="c-gray">电话</view>
					<view class="">{{info.mobile}}</view>
				</view>
				<view class="ticket_userinfo_cell" v-if="info.channel=='zh'">
					<view class="c-gray">粉丝嘉年华现场试乘预约</view>
					<view class="">{{info.project_name}}</view>
				</view>
				<view class="ticket_userinfo_cell">
					<view class="c-gray">试驾车型</view>
					<view class="">{{info.drive_car_series}}</view>
				</view>
				<view class="ticket_userinfo_cell">
					<view class="c-gray">试驾经销商</view>
					<view class="">{{info.company_info}}</view>
				</view>
				<view class="ticket_userinfo_cell">
					<view class="c-gray">预约时间</view>
					<view class="">{{info.create_time}}</view>
				</view>
				<view class="ticket_userinfo_cell" v-if="info.sign_status==1">
					<view class="c-gray">试驾时间</view>
					<view class="">{{info.sign_time}}</view>
				</view>
				<view class="ticket_userinfo_cell" v-if="info.sign_status==2">
					<view class="c-gray">取消时间</view>
					<view class="">{{info.sign_time}}</view>
				</view>
			</view>
			<view v-if="info.sign_status==0" class="group_public_btn_block mt-50" @click="cancelDrive()">取消试乘</view>
		</view>
		<view v-if="isDrawPop" class="guide_mask_box" @click="closeDrawPopup"></view>
		<view class="draw_pop" v-if="isDrawPop">
			<image class="win_pop_img" :src="picUrl+driverinfo.popup" mode="widthFix"></image>
			<view class="draw_pop_text">
				<view class="f-20 f-w mt-20">{{driverinfo.popup_title}}</view>
				<view class="f-18 mt-5">
					<text>{{driverinfo.popup_desc}}</text>
				</view>
			</view>
			<view class="draw_pop_btn" @click="openPrize">{{driverinfo.popup_button}}</view>
			<view class="draw_pop_close_icon_box">
				<uni-icons class="draw_pop_close_icon" @click="closeDrawPopup" type="close" color="#ffffff"
					size="50"></uni-icons>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getClubConfig,
		getDriverInfo,
		cancelDrive,
		getHuodongDriverInfo
	} from '@/api/motortime.js';
	let app = getApp()
	export default {
		data() {
			return {
				info: '',
				driverinfo: '',
				channel: 0,
				isDrawPop: false,
				test_drive_img: '',
				picUrl: app.globalData.picUrl,
				onlinePic: app.globalData.onlinePic,
			};
		},
		onShow() {
			if (!uni.getStorageSync('access_token')) {
				uni.navigateTo({
					url: '/pages/login/login'
				})
			}
		},
		onLoad(options) {
			this.id = options.drive_id
			this.channel = options.channel ? options.channel : 0
			if (uni.getStorageSync('clubconfig')) {
				this.test_drive_img = uni.getStorageSync('clubconfig').test_drive_img
				this.test_drive_car_series_arr = uni.getStorageSync('clubconfig').test_drive_car_series_arr
			} else {
				this.getClubConfig()
			}
			this.getDriverInfo()
			this.getHuodongDriverInfo()
		},
		methods: {
			getHuodongDriverInfo() {
				getHuodongDriverInfo({
					id: this.id,
				}).then(res => {
					if (res.state == 1) {
						this.driverinfo = res.data.info
						this.isDrawPop = res.data.info.popup_status == 1 ? true : false
					} else {
						uni.showToast({
							title: res.error[0],
							mask: true,
							icon: 'none',
							duration: 1500
						})
					}
				})
			},
			getDriverInfo() {
				getDriverInfo({
					id: this.id,
					channel: this.channel
				}).then(res => {
					if (res.state == 1) {
						this.info = res.data.info
					} else {
						uni.showToast({
							title: res.error[0],
							mask: true,
							icon: 'none',
							duration: 1500
						})
					}
				})
			},
			getClubConfig() {
				getClubConfig({}).then(res => {
					if (res.state == 1) {
						uni.setStorage({
							key: 'clubconfig',
							data: res.data,
							success: function() {}
						});
						this.test_drive_img = res.data.test_drive_img
						this.test_drive_car_series_arr = res.data.test_drive_car_series_arr
					} else {}
				})
			},
			cancelDrive() {
				cancelDrive({
					id: this.id
				}).then(res => {
					if (res.state == 1) {
						uni.showToast({
							title: '成功',
							mask: true,
							icon: 'success',
							duration: 1500
						})
						uni.setStorage({
							key: 'onload',
							data: true
						})
						this.getDriverInfo()
					} else {
						uni.showToast({
							title: res.error[0],
							mask: true,
							icon: 'none',
							duration: 1500
						})
					}
				})
			},
			closeDrawPopup() {
				this.isDrawPop = false
			},
			openPrize() {
				uni.navigateTo({
					url: '/pages/testdrive/testdriveprize?drive_id=' + this.id + '&channel=' + this.channel
				})
			}
		},
	}
</script>

<style lang="scss">
	.testdriveresult {
		.testdrive_bk_img {
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			right: 0;
			z-index: -1;
		}

		.testdrive_result_box {
			margin: 0 30rpx;
			margin-top: 65%;
			padding-top: 40rpx;
			background-color: #ffffff;

			.code_img_box {
				margin-top: 35rpx;
				text-align: center;

				.code_img {
					width: 190rpx;
					height: 190rpx;
				}

				.code_img_def {
					width: 190rpx;
					height: 190rpx;
					filter: grayscale(100%);
				}
			}

			.ticket_userinfo_box {
				margin: 35rpx 30rpx 0 30rpx;
				border-top: 1rpx dotted #AEAEAE;

				.ticket_userinfo_cell {
					font-size: 28rpx;
					margin-top: 20rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
				}
			}
		}

	}
</style>